package org.threadCase1;

public class threadDemo1 extends Thread{
    public static int ticket=0;
    @Override
    public void run(){
       while (true){
           synchronized (threadDemo1.class){
               if (ticket==1000){
                   break;
               }else {
                   try {
                       sleep(3000);
                   } catch (InterruptedException e) {
                       throw new RuntimeException(e);
                   }
                   ticket++;
                   System.out.println(getName()+"买了第"+ticket+"张票。剩"+(1000-ticket)+"张票");
               }
           }

       }
    }
}
